﻿@{
    ViewData["Title"] = "组织树";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}

<div id="eq-operate-organize" class="eq-operation">
    <div class="mdui-appbar mdui-appbar-fixed mdui-color-white mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>
            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>
            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>
            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div id="eq-operate-post" class="eq-operation">
    <div class="mdui-appbar mdui-appbar-fixed mdui-color-white mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>
            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedPostButtons"></module-buttons>
            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedPostButtons" is-float="true"></module-buttons>
            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div id="eq-operate-user" class="eq-operation">
    <div class="mdui-appbar mdui-appbar-fixed mdui-color-white mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>
            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedUserButtons"></module-buttons>
            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedUserButtons" is-float="true"></module-buttons>
            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>

<div class="mdui-appbar mdui-shadow-1 mdui-color-white">
    <div class="mdui-toolbar">
        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <div class="mdui-toolbar-spacer"></div>
        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>
    </div>
</div>

<div class="mdui-container-fluid mdui-m-t-1 mdui-m-b-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
    </div>
</div>

@section Scripts{
    <script>
        $(function () {
            gridTable();
            $('#refreshBtn').bind('click', function () {
                window.location.reload();
            });
        });

        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.organizeDataGrid({
                treeGrid: true,
                treeGridModel: "adjacency",
                ExpandColumn: "Code",
                url: '/SystemManage/Organize/TreeGridJson',
                mtype: "GET",
                datatype: "json",
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden: true },
                    { label: '名称', name: 'Name', width: 150 },
                    { label: '编码', name: 'Code', width: 100 },
                    { label: '类型', name: 'NodeType', width: 100 },
                    //{ label: '排序码', name: 'SortCode', width: 100 },
                    {
                        label: '创建时间', name: 'CreateTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    }

                ],
                height: getGridHeight(),
                shrinkToFit: true
            });

            $(window).resize(function () {
                //console.log(getGridHeight());
                $gridList.jqGrid('setGridHeight', getGridHeight() - 20);
            });

        }

        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建组织',
                url: '/SystemManage/Organize/Create',
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_edit() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '修改组织',
                url: '/SystemManage/Organize/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_details() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看组织',
                url: '/SystemManage/Organize/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_delete() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.deleteForm({
                url: '/SystemManage/Organize/Delete',
                param: { id: key },
                success: function (iframeId) {
                    window.location.reload();

                }
            })
        }

        function btn_editpost() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.modalOpen({
                id: 'formEditButton',
                title: '修改岗位',
                url: '/SystemManage/Post/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_detailspost() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看岗位',
                url: '/SystemManage/Post/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_deletepost() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                url: '/SystemManage/Post/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }

        function btn_edituser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
           

            $.modalOpen({
                id: 'formEditButton',
                title: '修改',
                url: '/SystemManage/User/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_detailsuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/User/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_deleteuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            

            $.deleteForm({
                url: '/SystemManage/User/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }

        function btn_postrelationuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
           
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }


            $.modalOpen({
                id: 'formEditButton',
                title: '岗位调动',
                url: '/SystemManage/User/PostRelation?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_rolerelationuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
           
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            

            $.modalOpen({
                id: 'formEditButton',
                title: '角色关联',
                url: '/SystemManage/User/RoleRelation?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_updateissystemuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定提升为系统用户吗？',
                url: '/SystemManage/User/UpdateIsSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateisnotsystemuser() {
            var key = $('#gridTable').jqGridRowValue().Id;
           
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定取消系统用户吗？',
                url: '/SystemManage/User/UpdateIsNotSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updatedisableduser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }


            $.deleteForm({
                prompt: '确定禁用用户吗？',
                url: '/SystemManage/User/UpdateDisabled',
                param: { userId: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateenableduser() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.deleteForm({
                prompt: '确定启用用户吗？',
                url: '/SystemManage/User/UpdateEnabled',
                param: { userId: key },
                success: function () {
                    window.location.reload();
                }
            })
        }
    </script>
}